package com.lindenvalley.de.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbSectionsHelper extends SQLiteOpenHelper {

	private static final int DB_VERSION = 3;
	  private static final String DB_NAME = "sections.db";

	  public static final String TABLE_NAME = "section";
	  
	  public static final String ID = "_id";
	  public static final String THEME_ID = "theme_id";
	  public static final String ROUND = "round";
	  public static final String QUESTION = "question_id";
	  public static final String ANSWER_TYPE = "answer_type";
	  public static final String ANSWERS = "answers";
	  public static final String IS_EXAM = "is_exam";
	  public static final String DATE = "date";
	  
	  private static final String CREATE_TABLE = 
		  "create table " + TABLE_NAME 
		  + " ( " + ID + " integer primary key autoincrement, "
		  + ROUND + " INTEGER, "
	      + THEME_ID + " INTEGER, " 
	      + QUESTION + " INTEGER, " 
	      + ANSWER_TYPE + " INTEGER, "
	      + ANSWERS + " TEXT, "
	      + IS_EXAM + " INTEGER, "	      
	      + DATE + " INTEGER DEFAULT (strftime('%s','now')))";
	  
	public DbSectionsHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(CREATE_TABLE);
	}
		

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		if (oldVersion < newVersion){
			db.execSQL("drop table " + TABLE_NAME);
			db.execSQL(CREATE_TABLE);
		}

	}

}
